package com.sgb.kjwl.view.ui.adapter.enterprise;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.core.util.Pair;

import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemCompanyListMakeoverBinding;
import com.sgb.kjwl.model.entity.enterprise.CompanyListEntity2;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.utils.DialogFunction;
import com.sgb.kjwl.utils.DialogHelper;
import com.swgk.core.event.EventConstant;
import com.sgb.kjwl.view.ui.activity.enterprise.MakeOverDetailActivity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class CompanyAdapter extends BaseRecycleAdapter<CompanyListEntity2> {
    Context context;
    private boolean isHome;

    public CompanyAdapter(Context context, List<CompanyListEntity2> datas, boolean isHome) {
        super(context, R.layout.item_company_list_makeover, datas);
        this.context = context;
        this.isHome = isHome;
    }

    @Override
    public void convert(ItemViewHolder holder, CompanyListEntity2 companyListEntity2) {
        ItemCompanyListMakeoverBinding itemCompanyListBinding = (ItemCompanyListMakeoverBinding) holder.getmBinding();
        itemCompanyListBinding.setViewModel(companyListEntity2);
        TextView tv_tag = holder.getItem().findViewById(R.id.tv_item_intel_prop_publish);
        switch (companyListEntity2.getUserType()) {
            case 0://个人
                tv_tag.setText("个人");
                tv_tag.setBackgroundResource(R.drawable.shape_radius_1_solid_bule);
                break;
            case 1://企业
                tv_tag.setText("企业");
                tv_tag.setBackgroundResource(R.drawable.shape_radius_1_solid_bule);
                break;
            case 2://团队
                tv_tag.setText("团队");
                tv_tag.setBackgroundResource(R.drawable.ractangle_radius_1_solid_yellow);
                break;
            default:
                tv_tag.setVisibility(View.GONE);
                break;
        }

        holder.setVisible(R.id.tv_item_intel_prop_hot, companyListEntity2.getLabel().contains("1"));
        holder.setVisible(R.id.tv_item_intel_prop_urgent_sale, companyListEntity2.getLabel().contains("2"));

        //临时调加区分是否大首页使用true 隐藏  false 显示
        if (isHome){
            itemCompanyListBinding.btnChat.setVisibility(View.GONE);
        }else {
            itemCompanyListBinding.btnChat.setVisibility(View.VISIBLE);
        }

        itemCompanyListBinding.btnChat.setOnClickListener(v -> {
            if (!DialogHelper.checkLogin()) {
                DialogHelper.showLoginDialogNew(context, EventConstant.EVENT_MAKE_OVER_JUMP, "温馨提示", "登录后可拨打电话,去登录", "登录");
                return;
            }
            DialogHelper.showDialog(context, "确认呼叫", companyListEntity2.getContact() + ":" + companyListEntity2.getPhone(), "确定", new DialogFunction() {
                @Override
                public void normalRoundDialog() {
                    ActivityJump.jumpToPhone(context, companyListEntity2.getPhone());
                }
            });
        });

        holder.itemView.setOnClickListener(v -> ActivityJump.jumpToActivity(context, MakeOverDetailActivity.class, Pair.create("detail", "公司"), Pair.create("id", companyListEntity2.getId())));
    }


}
